package de.hft_stuttgart.dsa.ctt.gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import de.hft_stuttgart.dsa.ctt.gui.view.IView;

/**
 * An instance of this class instantiates the graphical user interface.
 * 
 * @author Matthias Huber - MatthewHuber@web.de
 * 
 */
public class TimeTabler {

	/**
	 * The display of the user interface.
	 */
	private Display display;

	/**
	 * The shell of the user interface.
	 */
	private Shell shell;

	public TimeTabler() {
		display = new Display();

		shell = new Shell(display, SWT.SHELL_TRIM & ~SWT.RESIZE);
		shell.setText("CB-CTT");
		shell.setLayout(new FillLayout());	
	}
	
	/**
	 * Creates the main shell with the given size. This method also starts the
	 * SWT event loop.
	 * 
	 * @param width
	 *            The width of the shell.
	 * @param height
	 *            The height of the shell.
	 */
	public void create(int width, int height) {
		shell.setSize(width, height);
		shell.open();

		IView view = ViewFactory.createView(ViewEnum.TIMETABLERVIEW, shell);
		if (null != view) {
			view.show();
		}
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}

		display.dispose();
	}
}
